﻿using System;
using System.Security.Principal;

namespace uTILLIty.ADExtractor.Core.Formatters
{
	public class SidFormatter : IFormatter
	{
		public string Format(string attributeName, object value, string valueSeparator)
		{
			return new SecurityIdentifier((byte[])value, 0).Value;
		}

		public bool CanFormat(string attributeName)
		{
			return IsSidProperty(attributeName);
		}

		protected virtual bool IsSidProperty(string prop)
		{
			return prop.StartsWith("SID", StringComparison.InvariantCultureIgnoreCase) ||
			       prop.EndsWith("SID", StringComparison.InvariantCultureIgnoreCase);
		}
	}
}